home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / pratari.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-20  |  3.3 KB  |  187 lines

  1. /* atari.c */
  2. /* machine dependent code for atari */
  3.  
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. #include "prtypes.h"
  7. #define CANTALLOCATE "cant allocate "
  8. #define CRPLEASE "Carriage return please"
  9. #define NOCONFIGFILE "sprolog.inf missing using default configuration"
  10. #define CONFIG_FILE "sprolog.inf"
  11. #define YESUPPER 'Y'
  12. #define YESLOWER 'y'
  13.  
  14. extern FILE *Curr_outfile;
  15.  
  16. int Handle;
  17. int contrl[12];
  18. int intin[128];
  19. int ptsin[128];
  20. int intout[128];
  21. int ptsout[128];
  22.  
  23. char *os_alloc(how_much)
  24. zone_size_t how_much;
  25. {
  26.     char *ret,*lmalloc();
  27.     if((ret = lmalloc(how_much)) == NULL)
  28.     {
  29.         errmsg(CANTALLOCATE);
  30.         exit_term();
  31.         exit(1);
  32.         return(NULL);/* for stupid finicky compilers and lint */
  33.     }
  34.     else
  35.         return(ret);
  36. }
  37.  
  38. /* initialise terminal 
  39.  */
  40.  
  41. ini_term()
  42. {
  43. int i,phys_handle;
  44. short work_in[11],work_out[57],dummy;
  45.  
  46. appl_init();
  47. phys_handle = graf_handle(&dummy,&dummy,&dummy,&dummy);
  48. Handle = phys_handle;
  49.  
  50. for(i = 0; i < 10; i++)
  51.    work_in[i]=1;
  52.  
  53. work_in[10] = 2;
  54. v_opnvwk(work_in, &Handle, work_out);
  55. v_clrwk(Handle);
  56. v_enter_cur(Handle);
  57. }
  58.  
  59. /* leave terminal */
  60. exit_term()
  61. {
  62.     tty_pr_string(CRPLEASE);
  63.     getchar();
  64.     v_clsvwk(Handle);
  65.     appl_exit();
  66. }
  67.  
  68. /* output an error dialogue */
  69. errmsg(s)
  70. char *s;
  71. {
  72. /*
  73. static char errbuffer[256];
  74. sprintf(errbuffer,"[1][%s][OK]",s);
  75. form_alert(1,errbuffer);    
  76. */
  77. tty_pr_string(s);
  78. tty_pr_string("\n");
  79. }
  80.  
  81.  
  82. read_config(hs, strs, ds, tp, sbs, tmps, rs, ps)
  83. zone_size_t *hs, *strs, *ds, *tp, *sbs, *tmps;
  84. int *rs, *ps;
  85. {
  86.     FILE *ifp;
  87.  
  88.     if((ifp = fopen(CONFIG_FILE, "r")) == NULL)
  89.     {
  90.         errmsg(NOCONFIGFILE);
  91.         return(0);
  92.     }
  93.  
  94.     fscanf(ifp, "%ld %ld %ld %ld %ld %ld %d %d", hs, strs, ds, tp, sbs, tmps, rs, ps);
  95. #ifdef DEBUG
  96.     printf("%ld %ld %ld %ld %ld %ld %d %d", *hs, *strs, *ds, *tp, *sbs, *tmps, *rs, *ps);
  97.     getchar();
  98. #endif
  99.     return(1);
  100. }
  101.  
  102.  
  103. tty_pr_string(s)
  104. char *s;
  105. {
  106. #if TRACE_CAPABILITY
  107. extern FILE *Log_file;
  108.     if(Log_file){
  109.       fprintf(Log_file,"%s",s);
  110.         fflush(Log_file);
  111.         }
  112. #endif
  113.     printf("%s",s);
  114.     fflush(stdout);
  115. }
  116.  
  117. tty_getc()
  118. {
  119. #if TRACE_CAPABILITY
  120. extern FILE *Log_file;
  121.     if(Log_file){
  122.       fprintf(Log_file,"\n");
  123.         }
  124. #endif
  125. getchar();
  126. }
  127.  
  128. tty_getche()
  129. {
  130. return Cconin();
  131. }
  132. /*******************************************************************
  133.             pr_string()
  134.  *******************************************************************/
  135.  
  136. pr_string(s)
  137. char *s;
  138. {
  139. int len;
  140.  
  141. #if LOGGING_CAPABILITY
  142.     extern FILE *Log_file;
  143.     if (Log_file != NULL)
  144.     {
  145.     fprintf(Log_file, "%s", s);
  146.     fflush(Log_file);
  147.     }
  148. #endif
  149.     len = fprintf(Curr_outfile, "%s", s);
  150.     fflush(stdout);
  151. return(len);
  152. }
  153.  
  154.  
  155. /**************************** more_y_n() **********************************
  156.     Ask for confirmation.
  157.  ************************************************************************/
  158. /* a bit crude ... */
  159. more_y_n()
  160. {
  161.     tty_pr_string("More ?");
  162.     return(read_yes());
  163. }
  164.  
  165. /**************************** read_yes() *********************************
  166.         Return 1 iff user types y
  167. **************************************************************************/
  168. read_yes()
  169. {
  170. int c;
  171.  
  172. do
  173.  {
  174.  c = tty_getc();
  175.  }while(isspace(c));
  176.  
  177. while(tty_getc() != '\n');/* read rest of line */
  178.  
  179. if(c == YESLOWER || c == YESUPPER )
  180.   return(1);
  181. else
  182.  return(0);
  183. }
  184.  
  185. /* end of file */
  186.  
  187.